home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1501 < prev    next >
Encoding:
Text File  |  1996-08-06  |  4.5 KB  |  108 lines

  1. Path: beach.and.nl!usenet
  2. From: jos@and.nl (Jos A. Horsmeier)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  4. Subject: Re: Hungarian notation
  5. Date: 11 Jan 1996 10:26:08 GMT
  6. Organization: AND Operations Research B.V.
  7. Message-ID: <4d2ok0$69s@beach.and.nl>
  8. References: <30C40F77.53B5@swsbbs.com> <marnoldDJEvtJ.1Lx@netcom.com> <4aleun$jlk@ns.RezoNet.NET> <marnoldDJMDBG.CFz@netcom.com> <4asnkr$7b0@solutions.solon.com> <4ath75$e7i@barnacle.iol.ie> <4b4kij$svt@news.microsoft.com> <dewar.819489496@schonberg> <4bd <4cf8hf$8fe@hopi.gate.net> <4cgq30$c0v@weck.brokersys.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com>
  9. NNTP-Posting-Host: klepzeiker.and.nl
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4d21og$iab@news.xmission.com>, tknarr@xmission.com wrote:
  15. |In <4cvu68$2jb@macaw.cyberport.com>, tangent@cyberport.com (Warren Young) 
  16. |writes:
  17.  
  18. |>This is one of the reasons HN is useful.  By forcing the programmer to
  19. |>visit every place that the variable is used, the programmer has an
  20. |>opportunity to check the semantics of the variable's use.  If the type
  21. |>of the variable has changed, chances are that the semantics have
  22. |>changed as well.  How many times have you changed a variable's type to
  23. |fix something, only to break something else?
  24.  
  25. |I find this is false in practice. In general, when I change the declared
  26. |type of a variable, I'm doing the equivalent of changing an int to a long.
  27. |The result of that in the presence of HN is a massive amount of monkey-work
  28. |to visit and change every occurrence of the variable when the only reason
  29. |for the change is to replace iCount with lCount and nothing more. Since I
  30. |hate doing manual typographic changes like that and it can be difficult or
  31. |impossible to write a script to do it automatically in all files involved,
  32. |I find most often that it does not get done ( and I can't really blame
  33. |the people who didn't do it ).
  34.  
  35. |Changes in semantics do happen, but usually as a side-effect of a major
  36. |change in the fundamental way the code itself works, not as a side-effect
  37. |of a simple type change. As such they require code changes completely
  38. |above and beyond the variable names.
  39.  
  40. IMHO all HN tries to add to the language, is a (weak) notion of domains
  41. of objects. I thought (but correct me if I'm wrong) that HN adds a name
  42. prefix to an object name for the 'deeper notion' (read: the semantics or 
  43. domain); it does not prefix every object name with a short prefix 
  44. indicating the type used to implement the domain of an object.
  45.  
  46. Prefixing 'psz' to every zero terminated string is plain silly if we're
  47. talking about, say, employee names or beer brand names; something like 
  48. 'empnm' and 'beernm' should have been used instead. Only then, statements
  49. like:
  50.  
  51.     if (!strcmp(empnmBoss, beernmMyFavBeer))
  52.  
  53. trigger the reader that something fishy is going on here ... HN, as it
  54. is used now, doesn't add any clarity to the code at all, i.e. the statement:
  55.  
  56.     if (!strcmp(pszBoss, pszMyFavBeer))
  57.  
  58. just tells me that I want to compare my favorite beer and a boss's name,
  59. which is silly too, but it's not the 'psz' prefix that rings a bell here;
  60. it's just the 'Boss' and 'MyFavBeer' name parts that catch the eye.
  61.  
  62. Just adding domain name prefixes to the names of objects doesn't help
  63. anyone; notion of domains should be present in the language itself if
  64. one really wants domains, instead of just comparable types as implemented
  65. in the C language. Any (decent) C compiler feels perfectly fine if one
  66. feeds it something like:
  67.  
  68.     #include <stdio.h>
  69.     #include <string.h>
  70.  
  71.     typedef char* empnm_t;
  72.     typedef char* beernm_t;
  73.  
  74.     int main() {
  75.  
  76.     empnm_t empnmBoss     = "Clinton";
  77.     beern_t beernMyFavBeer= "Grolsch";
  78.  
  79.     if (!strcmp(empnmBoss, beernMyFavBeer))
  80.         printf("huh?\n");
  81.  
  82.     return 0;
  83.  
  84.     }
  85.  
  86. The type definitions don't help, the prefixes don't add any clarity
  87. and still the program would run fine. If domains would have been implemented
  88. in C, both typedefs could have been changed into something like:
  89.  
  90.     domain char* empnm_d;
  91.     domain char* beernm_d;
  92.  
  93. and the compiler would have complained while parsing the arguments of
  94. the strcmp() function, i.e. two different domains were compared ...
  95.  
  96. But if domains were implemented in C, we still don't need those explicit
  97. prefixes, because the compiler would have warned us about those domain
  98. violations, and, like you wrote above: if the semantics change, i.e. the
  99. domains change, one still has to change those prefixes accordingly if
  100. one used them ...
  101.  
  102. kind regards,
  103.  
  104. Jos aka jos@and.nl
  105. -- 
  106. Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
  107.  
  108.